package lab5_studentmanager;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class StudentDAO {

	public ArrayList<Student> getList() {
		ArrayList<Student> students = null;
		try {
			Connection conn = DatabaseConnection.getConnection();
			students = new ArrayList<>();

			Statement sta = conn.createStatement();
			ResultSet rs = sta.executeQuery("SELECT * FROM student");

			while (rs.next()) {
				Student student = new Student(rs.getInt("studentid"),
						rs.getString("name"), rs.getBoolean("male"),
						rs.getDate("birthday"), rs.getString("placeofbirth"),
						rs.getString("address"), rs.getString("depname"));
				students.add(student);
			}
			return students;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}

}
